/*okozWYO9HMx7batgGnxd4AuBK1wSr6VKuwaIC84nJyXAaId9spqimGEvI2VIiSQm*/
/*
 * @Descripttion:
 * @version:
 * @Author: Chendch
 * @Date: 2019-06-08 15:55:18
 * @LastEditors: Chendch
 * @LastEditTime: 2021-06-10 16:02:04
 */
/**
 * @desc   url参数转对象
 * @param  {String} url  default: window.location.href
 * @return {Object}
 */
export const parseQueryString = (url) => {
    let name, value;
    let str = location.href; //取得整个地址栏
    let num = str.indexOf("?");
    str = str.substr(num + 1); //取得所有参数
    var arr = str.split("&"); //各个参数放到数组里
    for ( let i = 0; i < arr.length; i++) {
        num = arr[i].indexOf("=");
        if (num > 0) {
            name = arr[i].substring(0, num);
            value = arr[i].substr(num + 1);
        if (pname === name)
            return decodeURIComponent(value);
        }
    }
    return "";
}

/**
 * @desc   localhost【主机+端口】
 * @return str
 */
export const urlHost = () => {
    return location.host;
}

/**
 * @desc   localhost【主机名】
 * @return str
 */
export const urlHostName = () => {
    return location.hostName;
}

/**
 * @desc   【端口】
 * @return str
 */
export const urlPost = () => {
    return location.post;
}

/**
 * @desc   http【协议】
 * @return str
 * **/
export const urlProtocol = () => {
    return location.protocol;
}

/**
 * 浏览器全屏
 */
export const fullScreen = () => {
    const docElm = document.documentElement;
    if(docElm.requestFullscreen) {
      docElm.requestFullscreen();
    }else if (docElm.mozRequestFullScreen) {//FireFox
      docElm.mozRequestFullScreen();
    }else if (docElm.webkitRequestFullScreen) {//Chrome等
      docElm.webkitRequestFullScreen();
    }else if (elem.msRequestFullscreen) {//IE11
      elem.msRequestFullscreen();
    }
  }

  /**
   * 浏览器退出全屏
   */
  export const exitFullScreen = () => {
    const docElm = document.documentElement;
    if(docElm.requestFullscreen) {
      docElm.exitFullscreen();
    }else if (docElm.mozRequestFullScreen) {//FireFox
      document.mozCancelFullScreen();
    }else if (docElm.webkitRequestFullScreen) {//Chrome等
      document.webkitCancelFullScreen();
    }else if (elem.msRequestFullscreen) {//IE11
      document.msExitFullscreen();
    }
  }

export const refreshTip = (param = {leavTip: "", refreshTip: ""}) => {
  window.addEventListener("beforeunload", function (e) {
    var  n  =  window.event.screenX  -  window.screenLeft; 
      var  b  =  n  >  document.documentElement.scrollWidth-20; 
    if(b  &&  window.event.clientY  <  0  ||  window.event.altKey) {//关闭
      //不是所有浏览器都支持提示信息的修改
      var confirmationMessage = param.leavTip || "系统可能不会保存您所做的更改";
      e.returnValue = confirmationMessage;
      return confirmationMessage;
    }else {
      //不是所有浏览器都支持提示信息的修改
      var confirmationMessage = param.refreshTip || "系统可能不会保存您所做的更改";
      e.returnValue = confirmationMessage;
      return confirmationMessage;
    }
  });
}



















/*okozWYO9HMx7batgGnxd4AuBK1wSr6VKuwaIC84nJyXAaId9spqimGEvI2VIiSQm*/
